package loggeri.android.namespace;

import java.util.ArrayList;
import java.util.Calendar;


import android.app.Activity;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;

public class ChainHandler {
	
	private ArrayList<Chain> chains = new ArrayList<Chain>();
	private View view;
	
	
	public ChainHandler(View view) {
		this.view = view;
	}
	
	
	
	public void luoKetju(Activity activity, String nimi) {
	 	Chain ketju = new Chain(nimi,activity);
        chains.add(ketju);
        ketju.lisaaNode(new Node(this.generoiPaiva(0),activity));
        view.ketjuNakyma(activity);
}
	
	
	public ArrayList<Chain> ketjut() {
		
		return chains;
	}
	
	
	public View getView() {
		return view;
	}

	public void setView(View view) {
		this.view = view;
	}

	public void luoPaiva(Activity activity ) {
		
		for(Chain c : chains) {	
			c.lisaaNode(new Node(this.generoiPaiva(2),activity));
			
		}
		view.paivaNakymat(activity);
		
	}
	
	public void tulostaKaikki(Activity activity) {
			for(Chain c : chains) {	
				c.tulostaNodet(activity);
			}
	}
	
	public String generoiPaiva(int step) {
		Calendar nyt = Calendar.getInstance();
		nyt.set(Calendar.DAY_OF_MONTH, nyt.get(Calendar.DAY_OF_MONTH) + step-10);
		
		Integer paiva = nyt.get(Calendar.DAY_OF_MONTH);
		
		Integer kk = nyt.get(Calendar.MONTH) + 1;
		Integer vuosi = nyt.get(Calendar.YEAR);
		
		
		String pvm = paiva.toString() + "." + kk.toString();;
		return pvm;
	}
	
	public void Nollaa() {
		for(Chain c : chains) {
				c.setStID(0);
		}
	}

}
